package com.xy.p2p.service.impl;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xy.common.page.Pagination;
import com.xy.core.service.impl.BaseServiceImpl;
import com.xy.core.util.BeanUtil;
import com.xy.p2p.dao.TmemberassetaccountdetailsDao;
import com.xy.p2p.model.Tmember;
import com.xy.p2p.model.Tmemberassetaccount;
import com.xy.p2p.model.Tmemberassetaccountdetails;
import com.xy.p2p.model.Tmemberrates;
import com.xy.p2p.model.Tuser;
import com.xy.p2p.service.TmemberassetaccountdetailsService;
import com.xy.p2p.service.TmemberratesService;

@Service
@Transactional
public class TmemberassetaccountdetailsServiceImpl extends BaseServiceImpl<Tmemberassetaccountdetails> implements
		TmemberassetaccountdetailsService {
	private TmemberassetaccountdetailsDao tmemberassetaccountdetailsDao;
	@Autowired
	private TmemberratesService tmemberratesService; 

	public TmemberassetaccountdetailsServiceImpl(TmemberassetaccountdetailsDao paramAppRoleDao) {
		super(paramAppRoleDao);
		this.tmemberassetaccountdetailsDao = paramAppRoleDao;
	}

	@Override
	public boolean checkExist(String paraName, String paraValue) {
		return tmemberassetaccountdetailsDao.checkExist("Tmemberassetaccountdetails", paraName, paraValue);
	}

	@Override
	public List<Tmemberassetaccountdetails> getTmemberassetaccountdetails(Map<String, Object> map) {
		return tmemberassetaccountdetailsDao.getTmemberassetaccountdetails(map);
	}
	@Override
	public Pagination getTmemberassetaccountdetailsByPage(Map<String, Object> map, int pageNo,
			int pageSize) {
		// TODO Auto-generated method stub
		return tmemberassetaccountdetailsDao.getTmemberassetaccountdetailsByPage(map, pageNo, pageSize);
	}
	 
   @Override
	public Tmemberassetaccountdetails save(Tmemberassetaccountdetails tmemberassetaccountdetails) {
//		tmemberassetaccountdetails.setModtime(new Date());
		if(tmemberassetaccountdetails.getMaadid()==null){
			//新增
        	return super.save(tmemberassetaccountdetails);
		}else{
			//更新
			Tmemberassetaccountdetails tmemberassetaccountdetails1=tmemberassetaccountdetailsDao.get(tmemberassetaccountdetails.getMaadid());
			try {
				BeanUtil.copyNotNullProperties(tmemberassetaccountdetails1, tmemberassetaccountdetails);
			} catch (Exception e) {
				e.printStackTrace();
			}  
			return super.save(tmemberassetaccountdetails1);
		}
	}
   
   	@Override
	public List<Tmemberassetaccountdetails> getUnPayRechargeList(Tmember tmember) {
		return tmemberassetaccountdetailsDao.getRechargeList(tmember);
	}

	@Override
	public double getUnPayRechargeFee(Tmember tmember) {
		double pay = 0;
		List<Tmemberassetaccountdetails> list = this.getUnPayRechargeList(tmember);
		for(Tmemberassetaccountdetails t : list){
			pay+=t.getTranamount();
		}
		Tmemberrates rate = tmemberratesService.getFee(Tmemberrates.RECHARGE_FEE);
		return pay*(rate.getRates());
	}
}